<script lang="ts">
import dayjs from 'dayjs'
import { Component, Vue } from 'vue-property-decorator'
import { getPersonStatusRecordsApi } from './service'

@Component({ name: 'PersonStatus' })
export default class ClockIn extends Vue {
  dataList: any[] = []

  async onLoad() {
    const { records } = await getPersonStatusRecordsApi({})
    this.dataList = records.map((i: any) => {
      if (i.DutyDate) {
        const currentDate = +dayjs().date()
        const dutyDate = +dayjs(i.DutyDate).date()
        if (dutyDate === currentDate) {
          i.DutyStatus = '值班中'
          i.Color = '#F56C6C'
        } else if (dutyDate > currentDate) {
          i.DutyStatus = '待班中'
          i.Color = '#F9AE3D'
          i.AttendanceLocation = ''
        } else {
          i.DutyStatus = '休息'
          i.Color = '#5AC725'
          i.AttendanceLocation = ''
        }
      } else {
        i.DutyStatus = '休息'
        i.Color = '#5AC725'
        i.AttendanceLocation = ''
      }
      return {
        ...i,
        DutyDate: i.DutyDate
          ? dayjs(i.DutyDate).format('YYYY-MM-DD hh:mm:ss')
          : '-'
      }
    })
  }
}
</script>

<template>
  <view class="page-container">
    <view v-if="dataList.length">
      <view
        v-for="i in dataList"
        :key="i.AttendanceID"
        class="rounded-4px text-first text-14px p-10px -mx-15px"
        style="border-bottom: 1px #ccc solid"
      >
        <view>姓名：{{ i.Name }}</view>
        <view class="mt-10px">
          状态：
          <text :style="{ color: i.Color }">{{ i.DutyStatus }}</text>
        </view>
        <view class="mt-10px">时间：{{ i.DutyDate }}</view>
        <view class="mt-10px" style="line-height: 18px">
          地点：{{ i.AttendanceLocation || '-' }}
        </view>
      </view>
    </view>
    <u-empty v-else mode="data" />
  </view>
</template>

<style scoped lang="scss">
.card_init {
  background-color: white;
  border-radius: 16rpx;
  min-height: 100rpx;
  padding: 20rpx;
}

.field-item:not(:last-child) {
  border-bottom: 1rpx solid #eeeeee;
}

.input-card {
  margin-top: 30rpx;
  padding: 0 30rpx;

  .field-item {
    position: relative;
    border-bottom: none;

    &:not(:last-child)::after {
      content: '';
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      bottom: 0;
      width: calc(100% - 64rpx);
      height: 1px;
      background-color: #e5e5e5;
    }

    .value {
      color: #333;
      text-align: right;
      font-size: 28rpx;
      line-height: 28rpx;
      /* 100% */

      &.active {
        color: #28c141;
      }

      &.select {
        padding-right: 32rpx;

        &::after {
          content: '';
          position: absolute;
          right: 32rpx;
          top: 50%;
          transform: translateY(-50%);
          width: 18rpx;
          height: 9rpx;
          background-size: 100% 100%;
        }
      }

      &.is-placeholder {
        color: #c5c5c5;
      }
    }
  }

  .input-card-wrapper {
    border-radius: 16rpx;
    overflow: hidden;
    background-color: #ffffff;
  }
}

.punch-in-box {
  padding: 100rpx 0 40rpx;
  text-align: center;

  .punch-in-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 214rpx;
    height: 214rpx;
    border-radius: 999rpx;
    background: linear-gradient(180deg, #8fbafc 0%, #4a91ff 100%);
    box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.1);
    font-size: 32rpx;
    color: #ffffff;

    &:active,
    &:focus {
      background: linear-gradient(180deg, #4a91ff 0%, #8fbafc 100%);
    }
  }

  .success-result-box {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 214rpx;
    height: 214rpx;
    border-radius: 999rpx;
    background: linear-gradient(180deg, #0eb841 0%, #21b849 100%);
    box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.1);
    font-size: 32rpx;
    color: #ffffff;

    &:active,
    &:focus {
      background: linear-gradient(180deg, #0eb841 0%, #21b849 100%);
    }
  }
  .address-info {
    text-align: left;
    margin-top: 90rpx;
    color: #999;
    font-size: 28rpx;
    line-height: 36rpx;
    position: relative;

    &::before {
      content: ' ';
      position: absolute;
      left: 0;
      top: 50%;
      width: 32rpx;
      height: 32rpx;
      transform: translateY(-50%);
      background-size: 100% 100%;
    }
  }
}

.qr-title {
  padding: 32rpx;
  color: #333;
  font-size: 32rpx;
  line-height: 28rpx;
  position: relative;

  &::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 32rpx;
    width: 18rpx;
    height: 9rpx;
    background-size: 100% 100%;
    transform-origin: center center;
  }

  &.expand {
    &::after {
      transform: translateY(-50%) rotate(180deg);
    }
  }
}

.qr-code-box {
  width: 450rpx;
  height: 450rpx;
  margin: 12rpx auto;

  .qr-code {
    width: 100%;
    height: 100%;
  }
}

.success-result-box {
  margin: 0 auto;
  width: 214rpx;
  height: 214rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  image {
    width: 90rpx;
    height: 90rpx;
  }

  .tips {
    font-size: 28rpx;
    color: #fff;
  }
}
</style>
